package cn.lds.j375.healthexam.interceptor;

import cn.lds.j375.healthexam.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

@Component
public class DoctorAuthorityInterceptior implements HandlerInterceptor {

    private static final Logger log = LoggerFactory.getLogger(DoctorAuthorityInterceptior.class);
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        User loginUser = (User) request.getSession().getAttribute("loginUser");

        if (loginUser.getRoleId() != 2){
            log.info("医生权限拦截器执行");
            request.setAttribute("err","您的权限无法访问该页面");

            request.getRequestDispatcher("/go_403").forward(request,response);
        }


        return true;
    }
}
